package com.example.practice4.Entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_student")
public class Student {
    @Column(name = "name")
    @Size(min=5,message="Name must be at least 5 characters long")
    private String name;

    @Id
    @Column(name = "id")
    @NotBlank(message = "学号不能为空")
    private String id;

    @Column(name = "grade")
    @NotBlank(message = "年级不能为空")
    private String grade;

    @Column(name = "profession")
    @NotBlank(message = "专业不能为空")
    private String profession;

    @Column(name = "college")
    @NotBlank(message = "学院不能为空")
    private String college;

    @ManyToMany(targetEntity = Course.class)
    @JoinTable(name= "t_relation"
            //joinColumns,当前对象在中间表的外键
            ,joinColumns = {@JoinColumn(name = "sid",referencedColumnName = "id")}
            //inverseJoinColumns，对方对象在中间表的外键
            ,inverseJoinColumns = {@JoinColumn(name = "cname",referencedColumnName = "name")})
    private List<Course> courses;

    }
